<%@ page language="java" pageEncoding="UTF-8"%><!DOCTYPE html>
<html>
<head>
<title>订单管理</title>
<jsp:include page="/admin/head.jsp"></jsp:include>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
</head>
<body>
	<jsp:include page="/admin/header.jsp"></jsp:include>
	<jsp:include page="/admin/left-menu.jsp?leftMenu=3"></jsp:include>
	<jsp:include page="/admin/footer.jsp"></jsp:include>

	<!--中间-->
	<section>
		<nav aria-label="breadcrumb">
			<ol class="breadcrumb">
				<li class="breadcrumb-item">管理首页</li>
				<li class="breadcrumb-item">内容管理</li>
				<li class="breadcrumb-item active">订单管理</li>
			</ol>
		</nav>

		<div class="pl-2 pr-2">
			<form class="form-inline keyForm">
				
				<div class="form-group mx-sm-1 mb-2">
					<label class="sr-only">关键字：</label> <input name="key" type="text"
						class="form-control" placeholder="搜索关键字">
				</div>
				
				<div class="form-group mx-sm-1 mb-2">
					<label class="sr-only">数量：</label> <select name="pageSize"
						class="form-control">
						<option value="5" ${page.rowMax==5?'selected':'' }>每页5条</option>
						<option value="10" ${page.rowMax==10?'selected':' ' }>每页10条</option>
						<option value="20" ${page.rowMax==20?'selected':' ' }>每页20条</option>
						<option value="50" ${page.rowMax==50?'selected':' ' }>每页50条</option>
					</select>
				</div>
				<button type="submit" class="btn btn-primary mb-2">
					<i class="fa fa-search"></i>
				</button>
			</form>

			<table class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<th scope="col">#</th>
						<th scope="col">用户名</th>
						<th scope="col">订单编号</th>
						<th scope="col">收货地址</th>
						<th scope="col">订单创建时间</th>
						<th scope="col">总价格</th>
						<th scope="col">订单状态修改</th>
						<th scope="col">订单详情查看</th>
					</tr>
				</thead>

					<tbody id="orderlist">
				<c:forEach items="${page['list'] }" var="vo" varStatus="i">
						<tr>
							<th>${i.index+1 }</th>
							<td>${vo.mallOrderName }</td>
							<td>${vo.mallOrderNum }</td>
							<td>${vo.mallOrderAddress }</td>
							<td>${vo.mallOrderDate }</td>
							<td>${vo.mallOrderCash }￥</td>
							<td>
								<div class="dropdown">
									<button
										class="btn btn-outline-primary btn-block dropdown-toggle"
										type="button" data-toggle="dropdown">${vo.mallOrderStatus }(修改)</button>
									<div class="dropdown-menu dropdown-menu-right">
										<a class="dropdown-item _update0"
											href="admin-order-update.let?orderId=${vo.mallOrderId }&status=1">未付款1</a> 
										<a class="dropdown-item _update1"
											href="admin-order-update.let?orderId=${vo.mallOrderId }&status=2">已付款2</a>
										<a class="dropdown-item _update2"
											href="admin-order-update.let?orderId=${vo.mallOrderId }&status=3">已发货3</a>
										<a class="dropdown-item _update3"
											href="admin-order-update.let?orderId=${vo.mallOrderId }&status=4">已签收4</a>
									</div>
								</div>
							</td>
							<td>
								<div class="dropdown">
									<button class="btn btn-primary _look" onclick="window.location='admin-order-look.let?orderId=${vo.mallOrderId }';" type="button">查看</button>
								</div>
							
							</td>
						</tr>
				</c:forEach>
					</tbody>


			</table>

		</div>
		<nav aria-label="Page navigation example">
			<ul class="pagination justify-content-center">
				<li class="page-item btn"><a class="page-link _start" aria-label="Previous">
				 <span aria-hidden="true">&laquo;</span>
				</a></li>
					<c:forEach items="${page.pages }" var="p" varStatus="i">
						<li class="page-item btn _page${p } ${p==page.current?'active':' '}"><a class="page-link"aria-label="Previous">
				 	<span aria-hidden="true">${p }</span>
					</a></li>
					</c:forEach>
				<li class="page-item btn"><a class="page-link _end" aria-label="Previous">
				 <span aria-hidden="true">&raquo;</span>
				</a></li>
			</ul>
		</nav>



	</section>
	<script type="text/javascript">
	for(let i=0;i<=3;i++){
		let cl = "._update"+i;
		console.info($(cl));
		$(cl).on("click", function() {
			console.info($(this).attr("href"));
			let href = $(this).attr("href")
			sys.confirm("您确定要修改这个订单状态吗？",function(r){
				if(r){
					$.get(
						href,
						function(data) {
							if (data.code == 200) {
								history.go(0);
								sys.toastr.success("修改成功");
							} else {
								sys.toastr.error(data.message);
							}
						}, "json"
					);
				}
			});
			return false;
		});
	}
		var pageMax = ${page.pageMax };
		var pages = ${page.pages.size() };
		var curr = ${page.current };
		var st = ${page.pages[0] };
		console.info(st);
		//console.info(s);
		$("._start").click(function(){
			//console.info("yyyhhh");
			$("#orderlist").html("");
			$.post(
				"admin-order-page.let",
				{"current":1},
				function(data){
					//console.info("yyyhhh");
					console.info(data);
					$.each(data.list,function(i,obj){
						//console.info(obj);
						//console.info("obj.articleTitle:"${obj.articleTitle });
						let h = $("#orderlist").html();
						var tr = "<tr><th>"+(i+1)+"</th><td>"+obj.mallOrderName +"</td><td>"+obj.mallOrderNum +"</td><td>"+obj.mallOrderAddress +"</td><td>"+obj.mallOrderDate+"</td><td>"+obj.mallOrderCash +"￥</td><td><div class='dropdown'><button class='btn btn-outline-primary btn-block dropdown-toggle' type='button' data-toggle='dropdown'>"+obj.mallOrderStatus +"</button><div class='dropdown-menu dropdown-menu-right'><a class='dropdown-item _update0' href='admin-order-update.let?orderId="+obj.mallOrderId +"&status=1'>未付款1</a> <a class='dropdown-item _update1' href='admin-order-update.let?status=2&orderId="+obj.mallOrderId +"'>已付款2</a><a class='dropdown-item _update2' href='admin-order-update.let?status=3&orderId="+obj.mallOrderId +"'>已发货3</a><a class='dropdown-item _update3' href='admin-order-update.let?status=4&orderId= "+obj.mallOrderId +"'>已签收4</a></div></div></td><td><div class='dropdown'><button class='btn btn-primary _look' onclick='window.location=`admin-order-look.let?orderId="+obj.mallOrderId+"`;' type='button'>查看</button></div></td></tr>";
						$("#orderlist").html(h+tr);
						console.info($("#orderlist"));
					})
				},"json"
			)
		});
		
		
		for(let i=st;i<=pages;i++){
			let cl = "._page"+i;
			console.info($(cl));
			$(cl).click(function(){
				//console.info("yyyhhh");
				$(cl).addClass("active").siblings().removeClass("active");
				$("#orderlist").html("");
				$.post(
					"admin-order-page.let",
					{"current":i},
					function(data){
						//console.info("yyyhhh");
						console.info(data);
						$.each(data.list,function(i,obj){
							//console.info(obj);
							//console.info("obj.articleTitle:"${obj.articleTitle });
							let h = $("#orderlist").html();
							var tr = "<tr><th>"+(i+1)+"</th><td>"+obj.mallOrderName +"</td><td>"+obj.mallOrderNum +"</td><td>"+obj.mallOrderAddress +"</td><td>"+obj.mallOrderDate+"</td><td>"+obj.mallOrderCash +"￥</td><td><div class='dropdown'><button class='btn btn-outline-primary btn-block dropdown-toggle' type='button' data-toggle='dropdown'>"+obj.mallOrderStatus +"</button><div class='dropdown-menu dropdown-menu-right'><a class='dropdown-item _update0' href='admin-order-update.let?orderId="+obj.mallOrderId +"&status=1'>未付款1</a> <a class='dropdown-item _update1' href='admin-order-update.let?status=2&orderId="+obj.mallOrderId +"'>已付款2</a><a class='dropdown-item _update2' href='admin-order-update.let?status=3&orderId="+obj.mallOrderId +"'>已发货3</a><a class='dropdown-item _update3' href='admin-order-update.let?status=4&orderId= "+obj.mallOrderId +"'>已签收4</a></div></div></td><td><div class='dropdown'><button class='btn btn-primary _look' onclick='window.location=`admin-order-look.let?orderId="+obj.mallOrderId+"`;' type='button'>查看</button></div></td></tr>";
							$("#orderlist").html(h+tr);
							console.info($("#orderlist"));
						})
					},"json"
				)
			});
		}
		
		$("._end").click(function(){
			//console.info("yyyhhh");
			$("#orderlist").html("");
			$.post(
				"admin-order-page.let",
				{"current":pageMax},
				function(data){
					//console.info("yyyhhh");
					console.info(data);
					$.each(data.list,function(i,obj){
						//console.info(obj);
						//console.info("obj.articleTitle:"${obj.articleTitle });
						let h = $("#orderlist").html();
						var tr = "<tr><th>"+(i+1)+"</th><td>"+obj.mallOrderName +"</td><td>"+obj.mallOrderNum +"</td><td>"+obj.mallOrderAddress +"</td><td>"+obj.mallOrderDate+"</td><td>"+obj.mallOrderCash +"￥</td><td><div class='dropdown'><button class='btn btn-outline-primary btn-block dropdown-toggle' type='button' data-toggle='dropdown'>"+obj.mallOrderStatus +"</button><div class='dropdown-menu dropdown-menu-right'><a class='dropdown-item _update0' href='admin-order-update.let?orderId="+obj.mallOrderId +"&status=1'>未付款1</a> <a class='dropdown-item _update1' href='admin-order-update.let?status=2&orderId="+obj.mallOrderId +"'>已付款2</a><a class='dropdown-item _update2' href='admin-order-update.let?status=3&orderId="+obj.mallOrderId +"'>已发货3</a><a class='dropdown-item _update3' href='admin-order-update.let?status=4&orderId= "+obj.mallOrderId +"'>已签收4</a></div></div></td><td><div class='dropdown'><button class='btn btn-primary _look' onclick='window.location=`admin-order-look.let?orderId="+obj.mallOrderId+"`;' type='button'>查看</button></div></td></tr>";
						$("#orderlist").html(h+tr);
						console.info($("#orderlist"));
					})
					//window.location="admin-article-page1.let?current="+data.current;
				},"json"
			)
		});
		
	</script>
</body>
</html>